package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.igas.bomp.facade.BompMchntQueryService;
import cc.rengu.igas.bomp.facade.bean.ImageInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntImageInfoBean;
import cc.rengu.igas.bomp.facade.enums.BompImageTypeEnum;
import cc.rengu.igas.bomp.facade.request.MchntImageInfoManageRequest;
import cc.rengu.igas.bomp.facade.request.MchntImageInfoQueryRequest;
import cc.rengu.igas.bomp.facade.response.MchntImageInfoQueryResponse;
import cc.rengu.igas.bomp.facade.result.Result;
import cc.rengu.redp.bizimpl.bean.LabelValueBean;
import cc.rengu.redp.bizimpl.enums.BompQueryTypeEnum;
import cc.rengu.redp.bizimpl.enums.BompTxnNumEnum;
import cc.rengu.redp.bizimpl.igas.bean.CompareDataBean;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.dao.UpmpBMchntImageInfoMapper;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpBMchntImageInfo;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpBMchntImageInfo;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpBMchntImageInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysSeqService;
import cc.rengu.redp.bizimpl.upmp.vo.ImageInfoVO;
import cc.rengu.redp.bizimpl.upmp.vo.MchntImageManageVO;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.common.utils.SortUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘玉亮.LL
 * @since 2021-06-22
 */
@Service
public class UpmpBMchntImageInfoServiceImpl extends ServiceImpl<UpmpBMchntImageInfoMapper, UpmpBMchntImageInfo> implements IUpmpBMchntImageInfoService {

    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Override
    public IPage<UpmpBMchntImageInfo> findByPage(QueryRequest request, UpmpBMchntImageInfo info) {
        try {
            LambdaQueryWrapper<UpmpBMchntImageInfo> queryWrapper = new LambdaQueryWrapper<>();
            UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
            if (null != user && user.isAdmin()) {
                String instId = info.getInstId();
                if (StringUtils.isBlank(instId)) {
                    instId = user.getInstId();
                }
                queryWrapper.likeRight(UpmpBMchntImageInfo::getInstId, instId);
            }
            if (StringUtils.isNotBlank(info.getMchntNo())) {
                queryWrapper.likeRight(UpmpBMchntImageInfo::getMchntNo, info.getMchntNo());
            }
            Page<UpmpBMchntImageInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);
            return this.page(page, queryWrapper);
        } catch (Exception e) {
            log.error("查询失败", e);
            return null;
        }
    }
    @Override
    public MchntImageInfoQueryResponse mchntImageInfoQuery(String instId, MchntImageInfoQueryRequest req, BompMchntQueryService bompQueryService, String traceNo, BompQueryTypeEnum queryType)throws RedpException {

        req.setHeader(CommonUtils.packageBompHeader(traceNo,BompTxnNumEnum.mchntImageInfoQuery.getType(),instId,queryType.getType()));

        try{
            log.trace("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易请求报文：" + JSON.toJSONString(req));

            Result<MchntImageInfoQueryResponse> response= bompQueryService.mchntImageInfoQuery(req);
            log.trace("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易返回报文：" + JSON.toJSONString(response));
            if(response.isSuccess()){
                MchntImageInfoQueryResponse resp = response.getResult();
                // 返回码：00-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.trace("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易成功");
                    return resp;
                }else {
                    if(Common.isNotBlank(resp)){
                        log.trace("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易成功");
                        return resp;
                    }else{
                        log.error("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易失败");
                        return null;
                    }
                }
            }else{
                log.error("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易没有获得返回信息");
                return null;
            }
        }catch (Exception e) {
            // TODO: handle exception
            log.error("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易出现异常，异常信息："+e.getMessage(),e);
            throw new RedpException("法人行["+instId+"],用户标识[" + req.getUserId() + "],商户号["+req.getMchntNo()+"]"+BompTxnNumEnum.mchntImageInfoQuery.getDesc()+"交易出现异常，异常信息："+e.getMessage());
        }
    }


    /**
     * 从 MchntImageInfoQueryResponse 转换成 MchntImageManageVO
     * @param entity
     * @param vo
     */
    @Override
    public void getMchntImageVo(MchntImageInfoQueryResponse entity, MchntImageManageVO vo){
        BeanUtils.copyProperties(entity,vo);
        List<MchntImageInfoBean> mchntImageInfoList=entity.getMchntImageInfoList();
        if(mchntImageInfoList == null || mchntImageInfoList.size() == 0){
            return;
        }
        for(MchntImageInfoBean mchntImage:mchntImageInfoList){
            //负责人手持身份证
            if(mchntImage.getImageType().equals(BompImageTypeEnum.HOLDING_CERT_PHOTO.getImageType())){
                //负责人手持身份证
                List<ImageInfoBean> holdingCert = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(holdingCert)){
                    ImageInfoVO img = new ImageInfoVO();
                    BeanUtils.copyProperties(holdingCert.get(0),img);
                    vo.setHoldingCert(img);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.SHOP_FRONT_PHOTO.getImageType())){
                //商户门头照
                List<ImageInfoBean> shopFront = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(shopFront)){
                    ImageInfoVO img = new ImageInfoVO();
                    BeanUtils.copyProperties(shopFront.get(0),img);
                    vo.setShopFront(img);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.FUND_MANAGE.getImageType())) {
                //资金管理关系证明照 list
                List<ImageInfoBean> fundManageList = mchntImage.getImageInfoList();
                if (CollectionUtils.isNotEmpty(fundManageList)) {
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for (ImageInfoBean bean : fundManageList) {
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean, img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setFundManageList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.BUSINESS_SITE_PHOTO.getImageType())){

                //经营场所照 list
                List<ImageInfoBean> premisesList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(premisesList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: premisesList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setPremisesList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.CREDIT_AUTH.getImageType())){
                //人行征信查询授权书 list
                List<ImageInfoBean> creditAuthList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(creditAuthList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: creditAuthList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setCreditAuthList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.CREDIT_REPORT.getImageType())){
                //征信报告 list
                List<ImageInfoBean> creditReportList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(creditReportList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: creditReportList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setCreditReportList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.NETWORK_VERIFY_REPORT.getImageType())){
                //身份证联网核查报告 list
                List<ImageInfoBean> networkVerifyList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(networkVerifyList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: networkVerifyList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setNetworkVerifyList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.OTHER_ELECTRON_IMAGE.getImageType())){
                //其他电子资料文件 list
                List<ImageInfoBean> otherFileList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(otherFileList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: otherFileList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setOtherFileList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.SIGN_PROTOCOL.getImageType())){
                //其他电子资料文件 list
                List<ImageInfoBean> SignList = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(SignList)){
                    List<ImageInfoVO> imgList = Lists.newArrayList();
                    for(ImageInfoBean bean: SignList){
                        ImageInfoVO img = new ImageInfoVO();
                        BeanUtils.copyProperties(bean,img);
                        img.setOptFlag(vo.getOptFlag());
                        imgList.add(img);
                    }
                    vo.setSignitAuthList(imgList);
                }
            }else if(mchntImage.getImageType().equals(BompImageTypeEnum.COLLECT_DEVICE.getImageType())){
                //商户门头照
                List<ImageInfoBean> cashier = mchntImage.getImageInfoList();
                if(CollectionUtils.isNotEmpty(cashier)){
                    ImageInfoVO img = new ImageInfoVO();
                    BeanUtils.copyProperties(cashier.get(0),img);
                    vo.setCashier(img);
                }
            }
        }
    }

    /**
     * 从 MchntImageManageVO 转换成 MchntImageInfoManageRequest
     * @param req
     * @param vo
     */
    @Override
    public void getMchntImageManage(MchntImageInfoManageRequest req, MchntImageManageVO vo){
        BeanUtils.copyProperties(vo,req);
        List<MchntImageInfoBean> mchntImageInfoList = Lists.newArrayList();

        if(Common.isNotBlank(vo.getHoldingCert())){
            List<ImageInfoBean> holdingCerts =new ArrayList<ImageInfoBean>();
            ImageInfoVO img = vo.getHoldingCert();
            ImageInfoBean bean = new ImageInfoBean();
            BeanUtils.copyProperties(img,bean);
            holdingCerts.add(bean);
            MchntImageInfoBean holdingCert=new MchntImageInfoBean();
            holdingCert.setImageType(BompImageTypeEnum.HOLDING_CERT_PHOTO.getImageType());
            holdingCert.setImageInfoList(holdingCerts);
            mchntImageInfoList.add(holdingCert);
        }

        if(Common.isNotBlank(vo.getCashier())) {
            List<ImageInfoBean> cashier =new ArrayList<ImageInfoBean>();
            ImageInfoVO img = vo.getCashier();
            ImageInfoBean bean = new ImageInfoBean();
            BeanUtils.copyProperties(img, bean);
            cashier.add(bean);
            MchntImageInfoBean shopFront = new MchntImageInfoBean();
            shopFront.setImageType(BompImageTypeEnum.COLLECT_DEVICE.getImageType());
            shopFront.setImageInfoList(cashier);
            mchntImageInfoList.add(shopFront);
        }


        if(Common.isNotBlank(vo.getShopFront())) {
            List<ImageInfoBean> shopFronts =new ArrayList<ImageInfoBean>();
            ImageInfoVO img = vo.getShopFront();
            ImageInfoBean bean = new ImageInfoBean();
            BeanUtils.copyProperties(img, bean);
            shopFronts.add(bean);
            MchntImageInfoBean shopFront = new MchntImageInfoBean();
            shopFront.setImageType(BompImageTypeEnum.SHOP_FRONT_PHOTO.getImageType());
            shopFront.setImageInfoList(shopFronts);
            mchntImageInfoList.add(shopFront);
        }

        if(CollectionUtils.isNotEmpty(vo.getFundManageList())){
            List<ImageInfoBean> fundManageList =new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getFundManageList();
            for(ImageInfoVO img: imgList){
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img,bean);
                fundManageList.add(bean);
            }
            MchntImageInfoBean fundManage=new MchntImageInfoBean();
            fundManage.setImageType(BompImageTypeEnum.FUND_MANAGE.getImageType());
            fundManage.setImageInfoList(fundManageList);
            mchntImageInfoList.add(fundManage);
        }

        if(CollectionUtils.isNotEmpty(vo.getPremisesList())){
            List<ImageInfoBean> premisesList =new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getPremisesList();
            for(ImageInfoVO img: imgList){
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img,bean);
                premisesList.add(bean);
            }
            MchntImageInfoBean premises=new MchntImageInfoBean();
            premises.setImageType(BompImageTypeEnum.BUSINESS_SITE_PHOTO.getImageType());
            premises.setImageInfoList(premisesList);
            mchntImageInfoList.add(premises);
        }

        if(CollectionUtils.isNotEmpty(vo.getCreditAuthList())) {
            List<ImageInfoBean> creditAuthList = new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getCreditAuthList();
            for (ImageInfoVO img : imgList) {
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img, bean);
                creditAuthList.add(bean);
            }
            MchntImageInfoBean creditAuth = new MchntImageInfoBean();
            creditAuth.setImageType(BompImageTypeEnum.CREDIT_AUTH.getImageType());
            creditAuth.setImageInfoList(creditAuthList);
            mchntImageInfoList.add(creditAuth);
        }
        if(CollectionUtils.isNotEmpty(vo.getCreditReportList())) {
            List<ImageInfoBean> creditReportList = new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getCreditReportList();
            for (ImageInfoVO img : imgList) {
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img, bean);
                creditReportList.add(bean);
            }
            MchntImageInfoBean creditReport = new MchntImageInfoBean();
            creditReport.setImageType(BompImageTypeEnum.CREDIT_REPORT.getImageType());
            creditReport.setImageInfoList(creditReportList);
            mchntImageInfoList.add(creditReport);
        }

        if(CollectionUtils.isNotEmpty(vo.getNetworkVerifyList())) {
            List<ImageInfoBean> networkVerifyList = new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getNetworkVerifyList();
            for (ImageInfoVO img : imgList) {
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img, bean);
                networkVerifyList.add(bean);
            }
            MchntImageInfoBean networkVerify = new MchntImageInfoBean();
            networkVerify.setImageType(BompImageTypeEnum.NETWORK_VERIFY_REPORT.getImageType());
            networkVerify.setImageInfoList(networkVerifyList);
            mchntImageInfoList.add(networkVerify);
        }

        if(CollectionUtils.isNotEmpty(vo.getOtherFileList())) {
            List<ImageInfoBean> otherFileList = new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getOtherFileList();
            for (ImageInfoVO img : imgList) {
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img, bean);
                otherFileList.add(bean);
            }
            MchntImageInfoBean otherFile = new MchntImageInfoBean();
            otherFile.setImageType(BompImageTypeEnum.OTHER_ELECTRON_IMAGE.getImageType());
            otherFile.setImageInfoList(otherFileList);
            mchntImageInfoList.add(otherFile);
        }


        if(CollectionUtils.isNotEmpty(vo.getSignitAuthList())){
            List<ImageInfoBean> signListList =new ArrayList<ImageInfoBean>();
            List<ImageInfoVO> imgList = vo.getSignitAuthList();
            for(ImageInfoVO img: imgList){
                ImageInfoBean bean = new ImageInfoBean();
                BeanUtils.copyProperties(img,bean);
                signListList.add(bean);
            }
            MchntImageInfoBean fundManage=new MchntImageInfoBean();
            fundManage.setImageType(BompImageTypeEnum.SIGN_PROTOCOL.getImageType());
            fundManage.setImageInfoList(signListList);
            mchntImageInfoList.add(fundManage);
        }

        req.setMchntImageInfoBeanList(mchntImageInfoList);
    }

    /**
     * 待审核时通过比较待审核临时数据、正式数据明细的id，分别得到得到新增、修改、删除的明细数据集合
     * @param tmps  待审核数据
     * @param formals  正式数据
     * @return
     */
    @Override
    public CompareDataBean getCompareFileById(List<ImageInfoVO> tmps, List<ImageInfoVO> formals) throws RedpException {

        Map<String,List<LabelValueBean>> updCompare = Maps.newHashMap();
        Map<String,List<LabelValueBean>> addCompare = Maps.newHashMap();
        Map<String,List<LabelValueBean>> delCompare = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(tmps)){
            for(ImageInfoVO tmp :tmps){
                boolean match = false;
                label1:for(ImageInfoVO formal :formals){
                    if(tmp.getId().equals(formal.getId())){
                        match=true;
                        List<LabelValueBean> compare = CommonUtils.compareData(tmp,formal,ImageInfoVO.class);
                        if(CollectionUtils.isNotEmpty(compare)){
                            updCompare.put(tmp.getId(),compare);
                        }
                        //跳出当前循环
                        break label1;
                    }
                }
                if(!match){
                    List<LabelValueBean> compare = CommonUtils.compareData(tmp,null,ImageInfoVO.class);
                    addCompare.put(tmp.getId(),compare);
                }
            }
        }
        if(CollectionUtils.isNotEmpty(formals)){
            for(ImageInfoVO formal :formals){
                boolean match = false;

                if(CollectionUtils.isNotEmpty(tmps)){
                    label1:for(ImageInfoVO tmp :tmps){
                        if(tmp.getId().equals(formal.getId())){
                            match=true;
                            //跳出当前循环
                            break label1;
                        }
                    }
                }
                if(!match){
                    List<LabelValueBean> compare = CommonUtils.compareData(null,formal,ImageInfoVO.class);
                    delCompare.put(formal.getId(),compare);
                }
            }
        }
        //jdk8流处理正式表中有，临时表中无的数据，则是需要删除的数据
/*        List<T> delList = formals.stream().filter(a->!tmps.stream().map(b->b.getId()).collect(Collectors.toList()).contains(a.getId())).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(delList)){
            delList.stream().forEach(item->{
                List<LabelValueBean> compare = CommonUtils.compareData(null,item,clazz);
                if(CollectionUtils.isNotEmpty(compare)){
                    delCompare.put(item.getId(),compare);
                }
            });
        }*/
        if(!addCompare.isEmpty()||!updCompare.isEmpty()||!delCompare.isEmpty()){
            return new CompareDataBean(addCompare,updCompare,delCompare);
        }else{
            return null;
        }
    }
    @Override
    public void compareImgList(MchntImageManageVO tmps, MchntImageManageVO formals, List<LabelValueBean> compareBeans) throws RedpException {

        List<LabelValueBean> removedCompareBeans = Lists.newArrayList();
        for(LabelValueBean bean:compareBeans){
            if("fundManageList".equals(bean.getElabel())){
                if(CollectionUtils.isNotEmpty(tmps.getFundManageList())&&CollectionUtils.isNotEmpty(formals.getFundManageList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getFundManageList(),formals.getFundManageList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }
            }else if("premisesList".equals(bean.getElabel())){
                if(CollectionUtils.isNotEmpty(tmps.getPremisesList())&&CollectionUtils.isNotEmpty(formals.getPremisesList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getPremisesList(),formals.getPremisesList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }

            } else if("creditAuthList".equals(bean.getElabel())){
                if(CollectionUtils.isNotEmpty(tmps.getCreditAuthList())&&CollectionUtils.isNotEmpty(formals.getCreditAuthList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getCreditAuthList(),formals.getCreditAuthList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }
            }else if("creditReportList".equals(bean.getElabel())){
                if(CollectionUtils.isNotEmpty(tmps.getCreditReportList())&&CollectionUtils.isNotEmpty(formals.getCreditReportList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getCreditReportList(),formals.getCreditReportList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }
            }else if("networkVerifyList".equals(bean.getElabel())){




                if(CollectionUtils.isNotEmpty(tmps.getNetworkVerifyList())&&CollectionUtils.isNotEmpty(formals.getNetworkVerifyList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getNetworkVerifyList(),formals.getNetworkVerifyList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }

            }else if("otherFileList".equals(bean.getElabel())){
                if(CollectionUtils.isNotEmpty(tmps.getOtherFileList())&&CollectionUtils.isNotEmpty(formals.getOtherFileList())){
                    CompareDataBean compareFileList = getCompareFileById(tmps.getOtherFileList(),formals.getOtherFileList());
                    //如果没有差异数据 则从compareBeans中删除
                    if(Common.isBlank(compareFileList)){
                        removedCompareBeans.add(bean);
                    }
                }
            }
        }
        compareBeans.removeAll(removedCompareBeans);
    }
    @Override
    public List<ImageInfoVO> getmchntImageList(MchntImageInfoQueryResponse resp) {
        List<ImageInfoVO> mchntList = new ArrayList<>();
        List<MchntImageInfoBean> mchntImageInfoList = resp.getMchntImageInfoList();
        for (MchntImageInfoBean mchntImageInfoBean : mchntImageInfoList) {
            String name = "";
            if (mchntImageInfoBean.getImageType().equals("00")) {
                name = "营业执照";
            } else if (mchntImageInfoBean.getImageType().equals("01")) {
                name = "法人证件照(人像面)";
            } else if (mchntImageInfoBean.getImageType().equals("02")) {
                name = "法人证件照(国微面)";
            } else if (mchntImageInfoBean.getImageType().equals("03")) {
                name = "签约协议照";
            } else if (mchntImageInfoBean.getImageType().equals("04")) {
                name = "单位证明函照片";
            } else if (mchntImageInfoBean.getImageType().equals("10")) {
                name = "商户门头照";
            } else if (mchntImageInfoBean.getImageType().equals("11")) {
                name = "经营场所照";
            } else if (mchntImageInfoBean.getImageType().equals("12")) {
                name = "手持证件照";
            } else if (mchntImageInfoBean.getImageType().equals("20")) {
                name = "征信报告";
            } else if (mchntImageInfoBean.getImageType().equals("21")) {
                name = "征信授权书";
            } else if (mchntImageInfoBean.getImageType().equals("22")) {
                name = "联网核查报告";
            } else if (mchntImageInfoBean.getImageType().equals("30")) {
                name = "结算账户照(商户结算净额)";
            } else if (mchntImageInfoBean.getImageType().equals("31")) {
                name = "结算账户照(商户手续费)";
            } else if (mchntImageInfoBean.getImageType().equals("99")) {
                name = "其他电子资料";
            }else if (mchntImageInfoBean.getImageType().equals("30")) {
                name = "结算账号正面/开户证明文件";
            }else if (mchntImageInfoBean.getImageType().equals("05")) {
                name = "资金管理关系证明照";
            }else if (mchntImageInfoBean.getImageType().equals("40")) {
                name = "收银台照片";
            }
            List<ImageInfoBean> imageInfoList = mchntImageInfoBean.getImageInfoList();
            for (ImageInfoBean imageinfobean : imageInfoList) {
                ImageInfoVO imageinfovo = new ImageInfoVO();
                String path = new String(Base64.getDecoder().decode(imageinfobean.getImageLocalPath()));
                String fileSuffix = path.substring(path.lastIndexOf(".") + 1);
                imageinfovo.setName(name + imageinfobean.getImageIndex() + "." + fileSuffix);
                imageinfovo.setImageType(mchntImageInfoBean.getImageType());
                imageinfovo.setImageLocalPath(imageinfobean.getImageLocalPath());
                imageinfovo.setId(imageinfobean.getId());
                mchntList.add(imageinfovo);
            }
        }
        return mchntList;
    }
    @Override
    public void updAlipayImageId(String instId, String mchntNo,String imageType,Integer imageIndex,String alipayImageId){
        LambdaUpdateWrapper<UpmpBMchntImageInfo> wrapper=new LambdaUpdateWrapper<>();
        wrapper.eq(UpmpBMchntImageInfo::getInstId,instId);
        wrapper.eq(UpmpBMchntImageInfo::getMchntNo,mchntNo);
        wrapper.eq(UpmpBMchntImageInfo::getImageType,imageType);
        wrapper.eq(UpmpBMchntImageInfo::getImageIndex,imageIndex);
        UpmpBMchntImageInfo info = new UpmpBMchntImageInfo();
        info.setAlipayImageId(alipayImageId);
        this.update(info,wrapper);
    }
}
